package com.ps.enums;

import lombok.Getter;

@Getter
public enum ErrorCode {
    // 系统级别错误码
    SUCCESS_LOGIN(0, "成功"),
    ERROR_DEFAULT(-99999, "发生异常，未知错误"),
    ERROR(-1, "系统繁忙，请稍后重试"),
    ERROR_INVALID_PARAMS(-2, "请求报文参数缺失或无效:"),
    ERROR_HTTP_REQUEST_FAIL(-3, "HTTP接口调用失败"),
    ERROR_EXCEPTION_DATA(-4, "数据异常"),
    ERROR_BIZ_HTTP_REQUEST_FAIL(-5, "第三方http请求返回异常"),
    NO_DATA(-6, "暂无数据"),


    //    登录
    LOGIN_FAILED(201, "手机号码或密码错误"),

    //    注册
    REGISTER_FAILED(206, "该手机号码已经注册"),

    //    验证码错误
    ERROR_VERIFY_CODE(202, "验证码错误"),



    // 计费系统
    PAYMENT_PASSWORD_IS_ABNORMAL(203,"支付密码不正确"),
    MONEY_LESS_THAN_ZERO(204,"金额的值不能是小于等于0的"),
    NEED_PASSWORD(205,"您并没有设置免密支付，需要输入支付密码才可以支付"),
    NEED_SET_PASSWORD(206,"请先设置支付密码"),
    ERROR_PAY_PASSWORD(207,"支付密码不正确"),
    BEFORE_PAY_PASSWORD_ERROR(208,"原支付密码输入有误"),
    ;


    private int code;
    private String msg;

    ErrorCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    /**
     * 枚举类型的判断和获取
     *
     * @param code 错误码
     * @return 返回错误码对应的枚举信息
     */
    public static ErrorCode statusOf(int code) {
        for (ErrorCode error : values()) {
            if (error.getCode() == code) {
                return error;
            }
        }
        return null;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg == null ? "" : msg.trim();
    }
}
